package com.czl.module_work.viewModel

import android.os.Bundle
import androidx.databinding.ObservableField
import com.blankj.utilcode.constant.PermissionConstants
import com.blankj.utilcode.util.PermissionUtils
import com.blankj.utilcode.util.ToastUtils
import com.czl.base.base.BaseViewModel
import com.czl.base.base.MyApplication
import com.czl.base.binding.command.BindingAction
import com.czl.base.binding.command.BindingCommand
import com.czl.base.config.AppConstants
import com.czl.base.data.DataRepository

class DevicePatrolViewModel(application: MyApplication, model: DataRepository) :
    BaseViewModel<DataRepository>(application, model) {

    val searchKey = ObservableField<String>()

    val btnMenu1Click: BindingCommand<Void> = BindingCommand(BindingAction {
        startContainerActivity(AppConstants.Router.Work.F_WORK_DEVICE_PATROL_ORDER)
    })


    val btnMenu2Click: BindingCommand<Void> = BindingCommand(BindingAction {
        startContainerActivity(AppConstants.Router.Work.F_WORK_PATROL_DISPATCH)
    })

    val btnMenu3Click: BindingCommand<Void> = BindingCommand(BindingAction {
        startContainerActivity(AppConstants.Router.Work.F_WORK_PATROL_AUDIT)
    })

    val btnScanClick: BindingCommand<Void> = BindingCommand(BindingAction {
        PermissionUtils.permission(PermissionConstants.CAMERA)
            .callback(object : PermissionUtils.SimpleCallback {
                override fun onGranted() {
                    startContainerActivity(AppConstants.Router.Work.F_WORK_SCAN)
                }

                override fun onDenied() {
                    ToastUtils.showShort("没有相机权限!")
                }
            }).request()
    })

    val btnQueryClick: BindingCommand<Void> = BindingCommand(BindingAction {
        startContainerActivity(
            AppConstants.Router.Work.F_WORK_DEVICE_PATROL_RESULT_ORDER,
            Bundle().apply {
                putInt(
                    AppConstants.BundleKey.WORK_ORDER_TYPE,
                    MyOrderDetailViewModel.FILTER_ORDER_TYPE_CHECK
                )
                putString(
                    AppConstants.BundleKey.WORK_ORDER_SEARCH_KEY,
                    searchKey.get().toString()
                )
            })
    })
}